#!/usr/bin/python2.6
import MySQLdb
import sys
import time
import hashlib
import fileinput
 

dbuser="monitor"
dbpass="monitor"
dbname="test"
socket="/u01/mysql/run/mysql.sock"

for lines in fileinput.input("iplist"):
    line=lines.split()
    ip1=line[0]
    ip2=line[1]
    sql="""select id,data_id,group_id,content,md5,src_user,src_ip,gmt_create,gmt_modified from config_info where content like '%%%s%%';"""%ip1
    print sql
    try:
        db=MySQLdb.connect(user=dbuser,passwd=dbpass,db=dbname,unix_socket=socket,charset="gbk")
        c=db.cursor()
    except MySQLdb.Error,e:
        print "connection failed!Error %d:%s"%(e.args[0],e.args[1])
    cnt=c.execute(sql)
    print 'ALl %s rows' ,cnt
    results = c.fetchall()
    print results
    for row in results:
            tmp=row[3].replace(ip1,ip2)
            tt="%s"%row[4]
            dd=hashlib.md5(tt).hexdigest()
            sql="""replace into config_info (id,data_id,group_id,content,md5,src_user,src_ip,gmt_create,gmt_modified ) values (%s,'%s','%s','%s','%s','%s','%s','%s','%s');""" %(row[0],row[1],row[2],tmp,dd,row[5],row[6],row[7],row[8])
            print sql
	    c.execute(sql)
    db.commit()
    db.close()
sys.exit(0)